package com.zisu.elasticsearch.ElasticSearch.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2020/11/30 10:09
 */

@Configuration //xml == bean
public class ElasticSearchClientConfig {
    //spring <bean id="restHighLevelClient" class = "RestHighLevelClient" >
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                //如果是集群就构建多个，不是集群就构建1个就行了
                RestClient.builder(
                        new HttpHost("192.168.0.179", 9200, "http"),
                        new HttpHost("192.168.0.183", 9200, "http"),
                        new HttpHost("192.168.0.184", 9200, "http")
                )
        );
        return client;
    }
}
